import requests
from bs4 import BeautifulSoup

class Admin:
    url = "http://49.235.56.17:8000/scorelist/manage"
    def __init__(self, password):
        self.password = password
        self.s = requests.Session()
    def get_csrf(self):
        html = self.s.get(Admin.url).text
        bs = BeautifulSoup(html, "lxml") 
        with open("tmp.html", "w", encoding="utf-8") as f:
            f.write(html)
        tag = bs.find("input", attrs={'name': "csrfmiddlewaretoken"})
        return tag.attrs['value']
    def push(self, user_list, score=0, reason=""):
        csrf = self.get_csrf()
        data = {
            'csrfmiddlewaretoken':csrf,
            'score_add': score,
            'password':self.password,
            'reason':reason,    
        }
        for x in user_list:
            data[x] = "on"
        res = self.s.post(url=Admin.url, data=data)
        print(res.status_code)
        # with open("points/tmp.html", "w", encoding="utf-8") as f: 
        #     print(res.text, file=f)


